type SESSION_KEY =
  | 'access_token'
  | 'user_info'
  | 'is_admin'
  | 'tablet_ws_url'
  | 'gait_analysis_ws_url'
  | 'ai_worker_ws_url'
  | 'gait_collector_ws_url'

export const SESSION = {
  get(key: SESSION_KEY) {
    return JSON.parse(sessionStorage.getItem(key) || 'null')
  },
  set(key: SESSION_KEY, value: unknown) {
    try {
      const serializedValue = JSON.stringify(value)
      sessionStorage.setItem(key, serializedValue)
    } catch (error) {
      this.remove(key)
      console.error('Error setting session storage:', error)
    }
  },
  remove(key: SESSION_KEY) {
    sessionStorage.removeItem(key)
  },
  clear() {
    sessionStorage.clear()
  },
}
